def ip(n):
    for i in range(2,int(n**0.5)+1):
          if n%i==0:
            return False
    return True
n=int(input())
if n<1000 or n>10000:
    n=0
    print(n)
else:
 n1=n//1000
 n2=(n//100)%10
 n3=(n//10)%10
 n4=n%10
 mp=0
 if ip(n1) and mp<n1: mp=n1
 if ip(n2) and mp<n2: mp=n2
 if ip(n3) and mp<n3: mp=n3
 if ip(n4) and mp<n4: mp=n4
 n12=n1*10+n2
 n13=n1*10+n3
 n14=n1*10+n4
 n23=n2*10+n3
 n24=n2*10+n4
 n34=n3*10+n4
 n123=n1*100+n2*10+n3
 n134=n1*100+n3*10+n4
 n124=n1*100+n2*10+n4
 n234=n2*100+n3*10+n4
 if ip(n12) and mp<n12: mp=n12
 if ip(n13) and mp<n13: mp=n13
 if ip(n14) and mp<n14: mp=n14
 if ip(n23) and mp<n23: mp=n23
 if ip(n24) and mp<n24: mp=n24
 if ip(n34) and mp<n34: mp=n34
 if ip(n123) and mp<n123: mp=n123
 if ip(n134) and mp<n: mp=n134
 if ip(n124) and mp<n: mp=n124
 if ip(n234) and mp<n: mp=n234
 if ip(n) and mp<n: mp=n
 print(mp)
